﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Willows.Model
{
	public abstract class SignalConnectorBase
		: TypedEntity, ISignal, IConnector
	{
		private string uniqueName;
		public string UniqueName
		{
			get { return uniqueName; }			
		}

		private ISignal output;
		public ISignal Output
		{
			get { return output; }
		}

		private ISignal input;
		public ISignal Input
		{
			get { return input; }
		}

		public void BindOutput(ISignal output)
		{
			if (this.output != null)
				throw new ArgumentException("Output of connector '" + LocalName + "' already bound to '" + this.output.LocalName + "'");

			this.output = output;
		}

		public void UnbindOutput(ISignal output)
		{
			if (this.output != output)
				throw new ArgumentException("Output not bound");

			this.output = null;
		}

		public void BindInput(ISignal input)
		{
			if (this.input != null)
				throw new ArgumentException("Input already bound");

			this.input = input;
		}

		public void UnbindInput(ISignal input)
		{
			if (this.input != input)
				throw new ArgumentException("Input not bound");

			this.input = null;
		}

		public abstract void DatapathMovedDownInHierarchy(Module newParent, Module oldParent);
		public abstract void DatapathMovedUpInHierarchy(Module newParent, Module oldParent);
		public abstract void Refine(RefinedModel.Model model);
		

		public SignalConnectorBase(Module parent, TypeRegistry typeRegistry, Type type, string name, string uniqueName) 
			: base(parent, typeRegistry, type, name)
		{
			this.uniqueName = uniqueName;
		}
	}
}
